package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.pay.model.Account;
import com.stylefeng.guns.modular.pay.model.Trans;
import com.stylefeng.guns.modular.pay.service.IAccountService;

/**
 * 支付控制器
 *
 * @author fengshuonan
 * @Date 2018-08-17 17:35:19
 */
@Controller
@RequestMapping("/account")
public class AccountController extends BaseController {

    private String PREFIX = "/pay/account/";

    @Autowired
    private IAccountService accountService;

    /**
     * 跳转到支付首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "account.html";
    }

    /**
     * 跳转到添加支付
     */
    @RequestMapping("/account_add")
    public String accountAdd() {
        return PREFIX + "account_add.html";
    }

    /**
     * 跳转到修改支付
     */
    @RequestMapping("/account_update/{accountId}")
    public String accountUpdate(@PathVariable Integer accountId, Model model) {
        Account account = accountService.selectById(accountId);
        model.addAttribute("item",account);
        LogObjectHolder.me().set(account);
        return PREFIX + "account_edit.html";
    }

    /**
     * 获取支付列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(Account account) {
    	 Page<Account> page = new PageFactory<Account>().defaultPage();
    	 //商户数据过滤
    	 if(ShiroKit.getUser().getRoleList().contains(6)){
    		 String ac = ShiroKit.getUser().getAccount();
    		 account.setMchNo(ac);
    	 }
         List<Account> result = accountService.list(page,account);
         page.setRecords(result);
         return super.packForBT(page);
    }

    /**
     * 新增支付
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Account account) {
        accountService.insert(account);
        return SUCCESS_TIP;
    }

    /**
     * 删除支付
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer accountId) {
        accountService.deleteById(accountId);
        return SUCCESS_TIP;
    }

    /**
     * 修改支付
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Account account) {
        accountService.updateById(account);
        return SUCCESS_TIP;
    }

    /**
     * 支付详情
     */
    @RequestMapping(value = "/detail/{accountId}")
    @ResponseBody
    public Object detail(@PathVariable("accountId") Integer accountId) {
        return accountService.selectById(accountId);
    }
}
